﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CMS
{
    public class InternalViewNews : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "InternalViewNews";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Title","Xem chi tiết bản tin");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId,"Description","");
            }
        }

        public override bool IsMainWebPart
        {
            get
            {
                return true;
            }
        }

        public override bool RunStandalone
        {
            get
            {
                return false;
            }
        }



        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            try
            {

                AjaxPro.Utility.RegisterTypeForAjax(typeof(InternalViewNews));
                Environment.Environments.CheckSessionTimeOut(true);


                string NewsId = (string)Environments.Request("NewsId");
                NewsCls
                    NewCls = new NewsBLL().CreateModel(Environments.ActiveLanguage, NewsId);


                string Html=
                    "<table class=cssInternalNews>";

                    string Subject = NewCls.Subject;
                    string Body = NewCls.Body;
                    string Source = NewCls.Source;
                    Source = Source.Trim();
                    string LargeImage = NewCls.ImageUrl;
                    string ImageUrl = Environments.HttpMediaRoot + "/media/" + Environments.PortalAlias + "/news/images/" + Environments.ActiveLanguage + "/" + LargeImage;
                    //string PathImage = Environments.WorkingPath + "\\media\\" + Environments.PortalAlias + "\\news\\images\\" + Environments.ActiveLanguage + "\\" + LargeImage;

                    DateTime EntryDate = NewCls.EntryDate;
                    bool Ok = false;
                    if (LargeImage.Trim().Length > 0) Ok = true;
                    //if (Ok)
                    //{
                    //    Ok = new System.IO.FileInfo(PathImage).Exists;
                    //}
                    Html += "<tr>";
                  
                    if (Ok)
                    {
                        Html +=
                                "     <td valign=top>";
                    }
                    else
                    {
                        Html +=
                                "     <td valign=top colspan=2>";
                    }
                    Html +=
                            "           <table>" +
                            "               <tr>" +
                            "                   <td><span class=cssInternalNewsSubject>" +  Subject + " - " + EntryDate.ToString("dd/MM/yyyy HH:mm") + "</subject></td>" +
                            "               </tr>" +
                            "               <tr>" +
                            "                   <td><span class=cssInternalNewsShortContent>" + Body + "</span></td>" +
                            "               </tr>";

                    if (Source.Trim().Length > 0)
                    {
                        Html +=
                                "               <tr>" +
                                "                   <td><span class=cssInternalNewsSource>" + ResourceBLL.GetText(WebPartId, "Source", "Nguồn tin") + ": " + Source + "</span></td>" +
                                "               </tr>";
                    }

                    Html +=
                                    "               <tr>" +
                                    "                   <td align=right><a href=\"javascript:history.back(-1);\" class=cssInternalNewsBack>" + ResourceBLL.GetText(WebPartId, "Back", "Quay lại")+"</a></td>" +
                                    "               </tr>";
                    Html +=
                            "           </table>" +
                            "     </td>" +
                            "</tr>"+
                    "</table>";

                return Html;
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }

               [AjaxPro.AjaxMethod]
        public string GetProcessingText()
        {
            string Url = Environment.Environments.GetActiveThemeUrl() + "/Global/Loading.gif";
            return "<img src=\"" + Url + "\"><a class=cssProcessing>" + ResourceBLL.GetText(WebPartId, "ProcessingText", "Đang đọc dữ liệu...") + "</a>";
        }
    }
}